package com.minelx.parallel;

import com.minelx.taskscheduler.CallbackTask;

import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

public class Executor<T> implements Runnable {

	private final Iterator<T> listPartitioner;

	private final Consumer<T> execution;

	private final CallbackTask task;

	public Executor(Iterator<T> listPartitioner, Consumer<T> execution, CallbackTask task) {
		this.listPartitioner = listPartitioner;
		this.execution = execution;
		this.task = task;
	}

	@Override
	public void run() {
		try {
			listPartitioner.forEachRemaining(execution);
		} catch (IllegalStateException ignored) {
		}
		task.done();
	}
}
